package com.yanqu.road.server.logic.activity.tradewar.condition.union;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.UnionRiseRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.tradewar.TradeWarActivityData;
import com.yanqu.road.server.logic.activity.tradewar.condition.BaseTradeWarActivityUnionRankCondition;
import com.yanqu.road.server.manger.activity.TradeWarActivityMgr;
import com.yanqu.road.server.manger.activity.TradeWarActivityRankMgr;
import com.yanqu.road.server.manger.rank.YRankMgr;

public class TradeWarActivityScoreUnionRankCondition extends BaseTradeWarActivityUnionRankCondition {

    public TradeWarActivityScoreUnionRankCondition(GamePlayer player, TradeWarActivityData activityData, ActivityConditionInfo conditionInfo) {
        super(player, activityData, conditionInfo);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.CrossTradeWarScoreRiseRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.CrossTradeWarScoreRiseRank.getValue(), handle);
    }

    @Override
    public boolean isCompleted(GamePlayer player) {
        return false;
    }

    @Override
    public void initDefaultValue() {
        setUnionRankActivityDefaultValue(player.getUserInfo().getUnionUid(), UnionRiseRankArgs.NOTIFY_TYPE_NORMAL);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        UnionRiseRankArgs args = (UnionRiseRankArgs) object;
        if(null != args) {
            ActivityInfo activityInfo = TradeWarActivityMgr.getInTimeActivityInfo(activityData.getActivityId());
            if(null != activityInfo) {
                setUnionRankActivityValue(getValue().add(args.getValue()), args.getUnionUid(), args.getType());
//                if (UnionRiseRankArgs.NOTIFY_TYPE_DELETE == args.getType()) {//解散商会
//                    TradeWarActivityRankMgr.removeUnionActivityRank(activityData.getActivityId(), args.getUnionUid());
//                    //todo 通知跨服
//                }
                YRankMgr.uploadUnionYRank(activityData.getUserActivityConditionData(getConditionId()), args.getUnionUid(), args.getType());
            }
        }
    }
}
